﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Money
{
    public class GridFormatTransactionMatch
    {
        private static IDataSet _dataInterface;

        public static void SetDataInterface(IDataSet dataInterface)
        {
            _dataInterface = dataInterface;
        }

        public GridFormatTransactionMatch()
        {
            MatchRule = new TransactionMatchRule();
            Format = new GridFormatRule();
        }

        public TransactionMatchRule MatchRule { get; set; }
        public GridFormatRule Format { get; set; }
        public string Details
        {
            get
            {
                String displayText = "";

                if (MatchRule.MinimumAmount != null)
                {
                    if (!String.IsNullOrWhiteSpace(displayText))
                    {
                        displayText += " ,";
                    }
                    displayText += "Min=" + MatchRule.MinimumAmount.ToString();
                }

                if (MatchRule.MaximumAmount != null)
                {
                    if (!String.IsNullOrWhiteSpace(displayText))
                    {
                        displayText += " ,";
                    }
                    displayText += "Max=" + MatchRule.MaximumAmount.ToString();
                }

                if (MatchRule.Type != null)
                {
                    if (!String.IsNullOrWhiteSpace(displayText))
                    {
                        displayText += " ,";
                    }
                    displayText += "Type=" + MatchRule.Type.ToString();
                }

                if (MatchRule.CategoryId != null)
                {
                    if (!String.IsNullOrWhiteSpace(displayText))
                    {
                        displayText += " ,";
                    }

                    if (_dataInterface != null)
                    {
                        displayText += "Category=" + _dataInterface.Categories.GetCategoryName((int)MatchRule.CategoryId);
                    }
                    else
                    {
                        displayText += "Category=" + MatchRule.CategoryId.ToString();
                    }
                }

                if (MatchRule.CategoryGroupId != null)
                {
                    if (!String.IsNullOrWhiteSpace(displayText))
                    {
                        displayText += " ,";
                    }

                    if (_dataInterface != null)
                    {
                        displayText += "Group=" + _dataInterface.Categories.GetCategoryName((int)MatchRule.CategoryGroupId);
                    }
                    else
                    {
                        displayText += "Group=" + MatchRule.CategoryId.ToString();
                    }
                }

                if (!String.IsNullOrWhiteSpace(MatchRule.Account))
                {
                    if (!String.IsNullOrWhiteSpace(displayText))
                    {
                        displayText += " ,";
                    }

                    displayText += "Account=" + MatchRule.Account.ToString();
                }

                if (!String.IsNullOrWhiteSpace(MatchRule.Description))
                {
                    if (!String.IsNullOrWhiteSpace(displayText))
                    {
                        displayText += " ,";
                    }

                    displayText += "Description=" + MatchRule.Description.ToString();
                }

                return displayText;
            }
        }
    }
}
